<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <title>配送关系管理（中心）</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
    
   
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>配送关系管理</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">采购目录管理</a></li>
            <li class="active"><a href="#">商品目录管理</a></li>
            <li class="active"><a href="#">配送关系管理</a></li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class="form-inline">
                    <div class="form-group form-group-xs">
                        <label for="txtDrugForm">商品编码：</label>
                        <input class="form-control" type="text" id="goodsCode" name="goodsCode" placeholder="商品编码" />
                    </div>
                    <div class="form-group form-group-xs">
                       &nbsp;&nbsp;&nbsp; <label for="txtDrugForm">药品编码：</label>
                        <input class="form-control" type="text" id="drugCode" name="drugCode" placeholder="药品编码" ></input>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="txtDrugForm">&nbsp;&nbsp;通用名：</label>
                        <input class="form-control" type="text" id="drugName" id="drugName" placeholder="通用名" />
                    </div>
                     <div class="form-group form-group-xs">
                        <label>配送企业：</label>
                        <input type="hidden" id="prodPompId" name="prodPompId" value="">
                        <input class="form-control" readonly="readonly" id="comp" name="comp" type="text" placeholder="生产企业" />
                    <a href="javascript:void(0)" onclick="selectComp();" class="btn btn-default btn-sm" >选择</a>
                   </div>
                    <div class="form-group form-group-xs">
                        <label>生产企业：</label>
                        <input type="hidden" id="prodPompId" name="prodPompId" value="">
                        <input class="form-control" readonly="readonly" id="comp" name="comp" type="text" placeholder="生产企业" />
                    <a href="javascript:void(0)" onclick="selectComp();" class="btn btn-default btn-sm" >选择</a>
                   </div>
                     <div class="form-group form-group-xs">
                        <label for="txtDrugForm">配送区域:</label>
                        <select class="form-control"  id="area1" name="area1">
                        </select>
                         <select class="form-control"  id="area2" name="area2">
                        </select>
                         <select class="form-control"  id="area3" name="area3">
                        </select>
                    </div>
                    <button type="button"  onclick="gridSerch()"  class="btn btn-success btn-sm">查&nbsp;询</button>
                </div>
            </div>
        </div>
         
        <table class="jqgrid" id="list4"></table>
        <div id="prowed2"></div>

            <div class="modal fade" id="selectComp" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header bg-primary">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h5 class="modal-title" id="exampleModalLabel">选择配送企业</h5>
                    </div>
                    <div class="modal-body">
                        <form>
                        <div class=" box box-success">
            <div class="box-body">
            <div class="form-inline">
                    <div class="form-group form-group-xs">
                         企业编码： 
                        <input class="form-control" type="text" id="compCode" placeholder="企业编码" />
                    </div>
                    <div class="form-group form-group-xs">
                         企业名称： 
                        <input class="form-control" type="text" id="compName" placeholder="企业名称" />
                    </div>
                  
                    
                    <button type="button" onclick="gridCompSerch()" class="btn btn-success btn-sm">查询</button>
                </div>
            </div>
        </div>
                        
                        <div class="form-group form-group-xs">
                                <table class="jqgrid col-sm-1" id="gridlist1"></table>
        <div id="gridpage1 col-sm-1"></div>
                            </div>
                        
                        
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" onclick="gridOk()" class="btn btn-primary btn-sm">选择</button>
                        <button type="button" class="btn btn-danger btn-sm" onclick="cleandata()">清空</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade" id="selectComp" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header bg-primary">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h5 class="modal-title" id="exampleModalLabel">选择生产企业</h5>
                    </div>
                    <div class="modal-body">
                        <form>
                        <div class=" box box-success">
            <div class="box-body">
            <div class="form-inline">
                    <div class="form-group form-group-xs">
                         企业编码： 
                        <input class="form-control" type="text" id="compCode" placeholder="企业编码" />
                    </div>
                    <div class="form-group form-group-xs">
                         企业名称： 
                        <input class="form-control" type="text" id="compName" placeholder="企业名称" />
                    </div>
                    
                    <button type="button" onclick="gridCompSerch()" class="btn btn-success btn-sm">查询</button>
                </div>
            </div>
        </div>
                        
                        <div class="form-group form-group-xs">
                                <table class="jqgrid col-sm-1" id="gridlist1"></table>
        <div id="gridpage1 col-sm-1"></div>
                            </div>
                        
                        
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" onclick="gridOk()" class="btn btn-primary btn-sm">选择</button>
                        <button type="button" class="btn btn-danger btn-sm" onclick="cleandata()">清空</button>
                    </div>
                </div>
            </div>
        </div>
          <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <table id="listy"></table>
                    <div id="prowedy"></div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" onclick="save();" class="btn btn-primary btn-sm">保存</button>
                        <button type="button" class="btn btn-danger btn-sm" data-dismiss="modal">关闭</button>
                    </div>
                </div>
            </div>
            
            
            
            
            <!-- 批量导入 -->
            <div class="modal fade" id="batchImport" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header bg-primary">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h5 class="modal-title" id="exampleModalLabel">导&nbsp;入</h5>
                    </div>
                    <div class="modal-body">
                        <form name="importform" id="importform" method="post" action="${ctx }/baseGoods/bathImportView.html" enctype="multipart/form-data">
                            <div class="form-group form-group-xs">
                                <label for="recipient-name" class="control-label">导入文件:</label>
                                <input type="file" name="goodFile" id="goodFile"/>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" onclick="bathImport();" class="btn btn-primary btn-sm">导入</button>
                        <button type="button" class="btn btn-danger btn-sm" data-dismiss="modal">关闭</button>
                        
                    </div>
                </div>
            </div>
        </div>
    <table class="jqgrid" id="list4"></table>
<div style="margin-top: 10px;"></div>
</section>
<%@ include file="/WEB-INF/component/commonJS.jsp"%>
<script type="text/javascript">
function openBathImport(){
    $("#goodFile").val("");
    $('#batchImport').modal({
            keyboard : true
        });
}
function bathImport(){
    var fileName = $.trim($("#goodFile").val());
    if (fileName == ""){
        $.HN.message.alert("请选择导入文件！", "消息", "error");
        return;
    }
    $("#importform").submit();
}
/**
$('#importform').ajaxForm({ 
    dataType: 'json', 
    
    success: function(returnData) {
    if(returnData == "success") {
        gridSerch();
        $.HN.message.alert('导入成功！', '提示信息', 'success');
        $("#batchImport").modal("hide");
    }else{
        $.HN.message.alert('导入失败，请重新添加！', '提示信息', 'error');
    }
   }    
});
*/
function switchStatus(goodsCode,status){
    $.post("${pageContext.request.contextPath}/baseGoods/switchStatus.html", {
        goodsCode : goodsCode, status : status
    }, function(result) {
        if (result.success) {
            gridSerch();
            $.HN.message.alert("操作成功！", "消息", "success");
        } else {
            $.HN.message.alert("操作失败！", "消息", "error");
        }
    }, "json")
}

function batchSwitchStatus(status){
    var rowIds = $("#list4").jqGrid("getGridParam", "selarrrow") || [];
    if (rowIds.length <= 0) {
        $.HN.message.alert("请选择要操作的行！", "消息", "error");
        return;
    }
    var list = [];
    for (var i=0; i<rowIds.length; i++) {
        rowId = rowIds[i];
        var rowdata = $("#list4").jqGrid('getRowData', rowIds[i]);
        list.push({"goodsCode":rowId,
            "status":status});
    }
    $.post("${pageContext.request.contextPath}/baseGoods/batchSwitchStatus.html", {
        "array" : json.jsonToString(list)
    }, function(result) {
        if (result.success) {
            gridSerch();
            $.HN.message.alert("操作成功！", "消息", "success");
        } else {
            $.HN.message.alert("操作失败！", "消息", "error");
        }
    }, "json")
}

$(function () {
jQuery("#list4").jqGrid({
    url: "getBaseDelByCentreList.html",
    mtype: "POST",
    datatype: "json",
    autowidth: true,
    multiselect:true,
    height: 250,
    colNames:['id','商品编码','通用名','剂型','规格','转换系数','单位','材质','生产企业','配送企业','药品来源','所属项目','配送地区','药品编码','状态','操作'],
    colModel:[
        {name:'delRelId',index:'delRelId',key:true,hidden:true, width:10, sorttype:"date", align:"center"},
        {name:'goodsCode',index:'goodsCode', width:100, sorttype:"date", align:"center",
        	formatter: function (val, opts, rowdata) {
        		return "<a href=\"toBaseDelByCentreGoods.html?delRelId="+rowdata.delRelId+"\">"+val+"</a>";
        		}	
        },
        {name:'drugName',index:'drugName', width:140, sorttype:false, align:"left"},
        {name:'formName',index:'formName', width:80, align:"center"},
        {name:'specName',index:'specName', width:80, align:"left",sorttype:false},
        {name:'factor',index:'factor', width:80, align:"center",sorttype:false},
        {name:'unit',index:'unit', width:40, align:"center",sorttype:false},
        {name:'materialName',index:'materialName', width:80, align:"center",sorttype:false},
        {name:'compName',index:'compName', width:180, sorttype:false, align:"left"},
        {name:'compName',index:'compName', width:190, sorttype:false, align:"left"},
        {name:'drugSource',index:'drugSource', width:80, sorttype:false, align:"center",
        	formatter : function(val, opts, rowdata) {
        		if (val == "1"){
                    return "国产";
                }else if (val == "2"){
                    return "进口";
                }else {
                    return "不详";
                }
            }    	
        },
        {name:'projectName',index:'projectName', width:160, sorttype:false, align:"left"},
        {name:'areaName',index:'areaName', width:120, sorttype:false, align:"center"},
        {name:'drugCode',index:'drugCode', width:100, sorttype:false, align:"center"},
        {name:'statusText',index:'statusText', width:80, align:"center",sorttype:false},
        {name:'oper',index:'oper', width:100, align:"center",
            formatter : function(val, opts, rowdata) {
            	var str = "";
                if (rowdata.statusText == "已确认"){
                    str = "<a href=\"javascript:void(0);\" onclick=\"switchStatus('"+rowdata.goodsCode+"','0');\">解除</a>";
                } else {
                    str = "<a href=\"javascript:void(0);\" onclick=\"switchStatus('"+rowdata.goodsCode+"','1');\">确认</a>";
                }
                str += "<a href='javascript:baseDelByCentreListLog(\""+rowdata.delRelId+"\");'>配送关系设置日志查询</a>";
                return str;
            }   
        }
    ],
     rowNum: 10,
     rowList: [10, 20, 50,100],
     rownumbers: true,
     multiselect: true,
     pager: "#prowed2",
     viewrecords: true,
     caption: "商品列表",
     editurl:"proPlanItemListHis.jsp",
     jsonReader: {
         repeatitems: false,
         id: "delRelId"
     }
    
});
     
    jQuery("#list4").jqGrid('navGrid',"prowed2",{edit:false,add:false,del:false});
    
    
    $("#drugCat").HNSelect({
        url: "${pageContext.request.contextPath}/selectController/getDicSys.html", data: { ID: '115' },defaultselect:'${form.patternType}',  defaultText: "<option value=''>请选择</option>",
    });
    
    $("#area1").HNSelect({
        url: "${pageContext.request.contextPath}/selectController/getArea.html", data: { ID: '000000' },defaultText: "<option value=''>请选择</option>",
        func: function () {
            $("#area2").HNSelect({
                parent_selector: "#area1", url: "${pageContext.request.contextPath}/selectController/getArea.html", dataid: "ID", defaultText: "<option value=''>请选择</option>",
                        func: function () {
                            $("#area3").HNSelect({
                                parent_selector: "#area2", url: "${pageContext.request.contextPath}/selectController/getArea.html", dataid: "ID", defaultText: "<option value=''>请选择</option>",
                            });
                        }
            });
        }
    });
    
});

function gridSerch() {
    var goodsCode = $.trim($("#goodsCode").val());
    var drugCode = $.trim($("#drugCode").val());
    var drugName = $.trim($("#drugName").val());
    var prodPompId = $.trim($("#prodPompId").val());
    var prodPompId = $.trim($("#prodPompId").val());
    var area = $.trim($("#area3").val());
	    if (area==""){
	        area = $.trim($("#area2").val());
	        if (area==""){
	            area = $.trim($("#area1").val());
	        }
	    }
    $("#list4").jqGrid('setGridParam',{  
        datatype:'json',
        postData:{"goodsCode":goodsCode,
                "drugCode":drugCode,
                "drugName":drugName,
                "prodPompId":prodPompId,
                "prodPompId":prodPompId,
                "areaName":area}
    }).trigger("reloadGrid"); //重新载入  
}

    
    
    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = parent.window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    }
    if(getQueryString("username")=="root"){
        $("#bedata1").show();
        $("#allDelete1").show();
        $("#bedata2").show();
        $("#allDelete2").show();
        
    }else if(getQueryString("username")=="yy001"){
        document.getElementById("yy001").style.display="";
    }else if(getQueryString("username")=="ps001"){
        document.getElementById("ps001").style.display="";
    }
    function editPsComp() {
        $('#editPsComp').modal({
            keyboard : true
        });
    }
    
    function stop(){
        var checked = false;
         $("input.cbox").each(function() {
             if($(this).is(":checked")) {
                 checked = true;
                 return false;
             };
         });
         
         if (!checked) {
             $.HN.message.alert('请选择要停用的条目', '提示信息', 'failed');
         }else{
     $.HN.message.confirm("确定要停用吗？", '', '').on(function (e) {
           if (e) {
               $.HN.message.alert('操作成功！', '提示信息', 'success');
               window.location.href="onSellDrugListCenter.jsp";
               
           }
       });
       }
    }
   $("#allDelete1").click(function(){
       var checked = false;
     $("input.cbox").each(function() {
         if($(this).is(":checked")) {
             checked = true;
             return false;
         };
     });
     
     if (!checked) {
         $.HN.message.alert('请选择要启用的条目', '提示信息', 'failed');
     }else{
         $.HN.message.confirm("确定要启用吗", '', '').on(function (e) {
              if (e) {
                  $.HN.message.alert('操作成功！', '提示信息', 'success');
                  window.location.href="onSellDrugListCenter.jsp";
                  
              }
          });
     }
     });
   
    function goJsp(n1){
        
        var opt ={
                url:"../../jsp/price/priceChangeExeDetailGrid.jsp",
                title:"newwindow",
style:{height:400,width:890,top:200,left:270}
        };
        $.HN.dialog.open(opt);
        
}
     
    $("#gridlist1").jqGrid({
        url: "${pageContext.request.contextPath}/stdCompinfo/stdCompinfoList.html",
        mtype: "POST",
        datatype: "json",
        autowidth: true,
        height: 255,
        shrinkToFit: false,
        colNames: ['id','企业编码','企业名称', '组织机构代码','法人代表'],
        colModel: [
            { name: 'compId',hidden:true,key:true, index: 'sdate', width: 90, align: "center"},
            { name: 'compCode', index: 'sdate', width: 90, align: "center"},
            { name: 'compName', index: 'sdate', width: 250, align: "left"},
            { name: 'orgCode', index: 'name', width:100, align: "center" },
            { name: 'lrName', index: 'name', width:80, align: "center" }
        ],
        rowNum: 10,
        rowList: [10, 20, 30],
        rownumbers: true,
        pager: "#gridpage1",
        //multiselect: true, 
        viewrecords: true,
        caption: "企业选择",    
        jsonReader: {
            repeatitems: false,
            id: "ids"
        }
    });
    $("#gridlist1").jqGrid('navGrid', '#gridpage1', { add: false, edit: false, del: false, search: false, refresh: false });
    $(window).trigger("resize");
    
    
    
    function selectComp(){
       
        $("#compCode").val("");
        $("#compName").val("");
     gridCompSerch();
       $('#selectComp').modal({
            keyboard : true
        });
       
      // window.open("${pageContext.request.contextPath}/stdDrug/toSelectComp.html?value=prodPompId&text=comp","newwin","dialogHeight: 200px; dialogWidth: 150px; dialogTop: 458px; dialogLeft: 166px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes;");
    }
    function gridCompSerch() {
        var compCode = $("#compCode").val();
        var compName = $("#compName").val();
        $("#gridlist1").jqGrid('setGridParam',{  
            datatype:'json',
            postData:{"compCode":compCode,
                    "compName":compName}
        }).trigger("reloadGrid"); //重新载入  
    }
    function gridOk(){
       var compId = $("#gridlist1").jqGrid('getGridParam', 'selrow');
        if (compId == null) {
           $.HN.message.alert('请至少选一行！', '提示信息', 'error');
            return;
        }
        var rowdata = $("#gridlist1").jqGrid('getRowData', compId);
        $("#prodPompId").val(compId);
        $("#comp").val(rowdata.compName);
        $("#selectComp").modal("hide");
        
    }
    function cleandata(){
       $("#prodPompId").val("");
        $("#comp").val("");
        $("#selectComp").modal("hide");
    }
    
    function switchStatus(goodsCode,status){
        $.post("${pageContext.request.contextPath}/baseDel/switchStatus.html", {
            goodsCode : goodsCode, status : status
        }, function(result) {
            if (result.success) {
                gridSerch();
                $.HN.message.alert("操作成功！", "消息", "success");
            } else {
                $.HN.message.alert("操作失败！", "消息", "error");
            }
        }, "json")
    }
    
    function baseDelByCentreListLog(id) {
        window.location.href = "${ctx}/baseDel/toBaseDelrelationByCentreListLog.html?delRelId="+id;
    }
    
</script>
</body>
</html>